<!-- eslint-disable vue/no-mutating-props -->
<template>
  <div>
    <!-- 通过ref拿到form的实例 -->
    <el-form ref="form" :model="form" label-width="100px" :inline="inline">
      <el-form-item
        v-for="item in formLabel"
        :key="item.label"
        :label="item.label"
      >
        <el-input
          v-if="item.type === 'input'"
          :placeholder="'请输入文字' + item.label"
          v-model="form[item.model]"
        ></el-input>
        <el-switch
          v-if="item.type === 'switch'"
          v-model="form[item.model]"
        ></el-switch>
        <dl-data-picker
          v-if="item.type === 'date'"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
          v-model="form[item.model]"
        ></dl-data-picker>
        <el-select
          v-if="item.type === 'select'"
          placeholder="请选择"
          v-model="form[item.model]"
        >
          <el-option
            v-for="item in item.opts"
            :key="item.value"
            :label="item.label"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- 使用插槽进行扩展 -->
      <el-form-item><slot></slot></el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'CommonForm',
  data () {
    return {}
  },
  //props用于接受相关属性的参数
  props: {
    formLabel: Array, //表单相关配置
    form: Object, //接受数据
    inline: Boolean //表单布局
  }
}
</script>

<style>
.el-form-item {
  margin: 0;
}
</style>
